<?php
/**
 * 
 * 所有用户信息管理
 * xysc users Version1.0
 * ==================================
 * Copy 2016-2017
 * Web:www.xjh7.com
 * ==================================
 * Author:xjh
 * Date:2016-05-31
 * model() 创建模型对象，静态
 * tableName() 返回表名
*/

class Useradmin
 extends CActiveRecord {
	/**
	 *返回当前模型对象的方法 
	 */
	public static function model($className = __CLASS__){
		return parent::model($className);
	}
	/**
	 * 返回当前表名
	 */
	public function tableName(){
		return '{{user}}';
	}
	 
	
	/**
	 * 获取角色信息
	 */
	public function getRoleInfo(){
		$cmodel = new CCCModel();
		$_sql = "SELECT role_id,role_name FROM {{role}}";
		$result = $cmodel -> sel($_sql);
		return $result;
	}
	
	/**
	 *获取所有用户信息
	 *
	 */
	public function getAllUserInfos(){
		$cmodel = new CCCModel();
		$_sql = "SELECT a.user_id,a.user_name,(SELECT b.role_name FROM {{role}} b WHERE b.role_id=a.role_id)as role_name FROM {{user}} a";
		$result = $cmodel -> sel($_sql);
		return $result;
	}
	
	
	/**
	 * 添加用户信息(基本)
	 */
 	public function adduser(){
		$cmodel = new CCCModel();
		$_sql = "INSERT INTO {{user}} (`user_name`,`user_password`,`role_id`,`active`,`user_tel`,`user_email`,`user_register`,`user_last_ip`)VALUES('".$_POST['user_name']."','".$_POST['user_password']."','".$_POST['role_id']."','".$_POST['active']."',0,0,NOW(),'0')";
		$result = $cmodel -> upd($_sql);
		return $result;
	}
	
	/**
	 * @author xjh
	 * 根据id查询user信息
	 */
	public function getUserInfoById($user_id){
		$cmodel = new CCCModel();
		$sql = "SELECT * FROM {{user}} WHERE user_id=$user_id";
		$result = $cmodel -> sel($sql);
		return $result;
		
	}
	
	/**
	 * 修改用户信息方法
	 * @author xjh
	 * @param int $pages_id
	 */
	public function updateUser($user_id){
		$cmodel = new CCCModel();
		if($_POST['user_password'] != ''){
			$_sql = "UPDATE {{user}} set user_name='".$_POST['user_name']."',user_password='".$_POST['user_password']."',role_id='".$_POST['role_id']."',active='".$_POST['active']."' WHERE user_id=".$user_id;
		}else{	
			$_sql = "UPDATE {{user}} set user_name='".$_POST['user_name']."',role_id='".$_POST['role_id']."',active='".$_POST['active']."' WHERE user_id=".$user_id;
		}
		$result = $cmodel -> upd($_sql);
		return $result;
	}
	/**
	 * 删除菜单信息方法
	 * @author xjh
	 * @param int $pages_id
	 */
	public function deletePageInfoById($pages_id){
		$cmodel = new CCCModel();
		$sql = "UPDATE {{pages}} set active = 0 WHERE pages_id=$pages_id";
		$result = $cmodel -> upd($sql);
		return $result;
	}
	
	
}
	
?>